package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author chenchuang
 * @Date 2024-08-27
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController extends BaseController {

    @Autowired
    private NursingLevelService nursingLevelService;

    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult<List<NursingLevel>> listAll() {
        List<NursingLevel> nursingLevelList = nursingLevelService.getAll();
        return success(nursingLevelList);
    }

    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.add(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = nursingLevelService.getByPage(name,status,pageNum,pageSize);
        return success(nursingLevelVoPageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable("id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult update(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.update(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        nursingLevelService.updateStatus(id,status);
        return success();
    }
}
